home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / appl / browser.sit / Browser tech note < prev    next >
Text File  |  1987-05-14  |  8KB  |  173 lines

  1.   Technical note on the Browser - 1987 April 12 - Updated 1987 Apr 29 & May 14
  2.  
  3.              by Mark^Zimmermann
  4.                 9511 Gwyndale Drive
  5.                 Silver Spring, MD 20910
  6.                 301-565-2166
  7.                 science@@nems.arpa - 75066,2044 on CompuServe
  8.  
  9.      This note is meant to describe briefly the design philosophy and
  10. algorithms used in Browser (a.k.a. Tiny Browser, Recall, Boxcars, etc.)
  11. as of today.  For additional details, contact me at the above
  12. addresses, or consult the source code of the program itself.
  13.  
  14.  
  15. OVERVIEW
  16.  
  17.      The Browser goal is to provide a user with an exceedingly
  18. simple, exceeding fast environment in which to be exceedingly
  19. productive in working with very large (many megabytes) but very
  20. disorganized files of free-text information.  In order to be useful
  21. in the real world, the program must be up and running (not just a
  22. research project) this year.  It must run on real hardware,
  23. available to real people, not on systems too expensive,
  24. experimental, or unreliable to use.  It must not require its users
  25. to go through gyrations in order to get data into or out of the
  26. program.  It must not assume that data comes in neat, tidy,
  27. well-formatted bundles.
  28.  
  29.      Ideally, the Browser should run on any piece of hardware
  30. that is available.  Practically, the first system that it is being
  31. developed on is the Apple Macintosh, because I have one and because
  32. it has an excellent user interface and programming environment for
  33. developing the Browser.  A near-term goal is to transport some
  34. version of the program to the IBM-PC and compatibles, and to the
  35. Sun Workstation.  Longer term goals are to make all or part of it
  36. run on mainframe IBM computers, Cray supercomputers, etc.
  37.  
  38.      The program at present is written in MacForth Plus and runs on
  39. any Macintosh system with 512KB of memory or more, including the
  40. Mac II.  It consists of about 2,000 lines of Forth code, heavily
  41. commented.  Run the program to get an idea of what features have
  42. been implemented and what the user interface looks like ... they
  43. change from week to week as I put more things in.
  44.  
  45.  
  46. DATA STRUCTURES
  47.  
  48.      In keeping with the spirit of the program, as well as the
  49. simple-mindedness of the programmer, there is really only one data
  50. structure used in the Browser, and it is highly primitive. 
  51. Above all, locality of reference is the Holy Grail -- with the idea
  52. of enhancing the program's speed when running with devices such as
  53. optical disks, which currently have rather slow rates for moving
  54. their heads around on the media.  Side-effects of the simple
  55. approach are good execution speed, simplicity in sorting and
  56. accessing the data, and ease of debugging.  The main penalty is
  57. wasted disk storage space -- a penalty that is becoming
  58. increasingly irrelevant as big, fast mass media become cheaper
  59. every day.
  60.  
  61.      The inputs to the Browser are two types of files:  text
  62. files and index files.  Text files consist of ASCII characters, as
  63. usual.  An index file consists of index records of 16 bytes each:
  64.  - 4 bytes of pointer into the text file being indexed, and
  65.  - 12 bytes of index key
  66. The index key is extracted from the text file beginning at the
  67. pointer value, turned into all capital letters, and filled out with
  68. blanks from the end of the word indexed to the end of the 12 bytes. 
  69. These 16-byte index records are then simply arranged in
  70. alphabetical order, sorted by their index key field, in a linear
  71. array -- the index file.
  72.  
  73.      For a specific example, if the input file consisted of the
  74. words "Now is the time now" then the index file would look like:
  75.    4IS          0NOW         16NOW         7THE         11TIME
  76. where there is obviously a lot of wasted blank space.
  77.  
  78.      The recent addition of a Subindex search capability, described
  79. below, arguably adds another data structure to the Browser; see the
  80. discussion in that section for details.
  81.  
  82.  
  83. ALGORITHMS
  84.  
  85.      Similar to the discussion of data structures above, there
  86. is only one algorithm that deserves the name in the current 
  87. Browser, and that algorithm is many decades old and very simple. 
  88. In order to sort the index of words into alphabetical order, the
  89. program executes a classical radix sort.
  90.  
  91.      This is the same sort used on old punched-card sorters. 
  92. Starting with the rightmost of the 12 columns of the index key
  93. field, we take the index records and throw them into bins
  94. corresponding to the letter in that column.  We take the contents
  95. of those bins and stack them together, and repeat the process, this
  96. time using the letter in column 11 to determine which bin each card
  97. goes into.  Etc., etc., until the final pass on column 1 ends with
  98. all of the cards, I mean index records,  sorted.  Try it out by
  99. hand to get an idea of how it works, or read about it in any
  100. standard textbook.
  101.  
  102.      The radix sort has many advantages besides its simplicity.  It
  103. takes time that grows linearly with the number of index records to
  104. be sorted -- thus, there is no logarithmically-increasing speed
  105. penalty.  It is a stable sort, in that identical words will end up
  106. in the index appearing in the same order in which they appeared in
  107. the original file.  (That is convenient for the user who wants to
  108. browse sequentially through the data.)  The radix sort vectorizes
  109. well, an advantage when sorting on supercomputers or other
  110. vector-oriented machines.  Additionally, the radix sort can be used
  111. with a very simple data buffering structure, since information is
  112. read in strictly sequentially from mass storage, and is moved out
  113. in simple, repetitive patterns.
  114.  
  115.      The simple radix sort does suffer from one disadvantage:  it
  116. requires free space on the disk equal in size to the file being
  117. sorted.  That space is used for the storage of the "bins" into
  118. which items are thrown during the 12 sorting passes, and it is free
  119. again at the end of the sort.  I have not found that requirement
  120. for space to be a significant problem.  (In most cases, a user
  121. would like to keep some space free for later data accumulation,
  122. note-taking, etc., and so it seems unlikely that a file that
  123. occupied all of free disk space would ever need to be sorted.)
  124.  
  125.      Other than the radix sort, the only other computational
  126. technique that comes to mind as being used in the Browser is
  127. the binary search, in order to respond to a user's keystrokes in
  128. the Index Window display.  Does that count as an "algorithm"?
  129.  
  130.  
  131. SUBINDEX IMPLEMENTATION
  132.  
  133.      Versions of Browser after v.240 have a new capability:  Subindex
  134. searching.  If a user wants to find, for example, all occurrences of
  135. the words "computer" or "computers" near the word "Apple", it is now
  136. easy to do so without being forced to visually scan through a large
  137. number of irrelevant context items.
  138.  
  139.      The way I have implemented that is to use a simple linear
  140. array of flag bits, one for every 32 characters (bytes) in
  141. the original text file.  If a flag bit is set to 1, then that
  142. region of the database is "valid"; if 0, it is "invalid".  The
  143. Index Window now counts and displays occurrences of indexed words
  144. in valid regions of the data file.  That information is shown along
  145. with the total number of occurrences of items in the database (including
  146. valid and invalid regions).  A user can clear ("Empty") out the working
  147. subindex, can set it to equal the entire database ("Fill"), and can
  148. take the complement of the subindex ("Invert", a boolean NOT operation).
  149.  
  150.      The bit array for the new Index window starts out all 0's.  As a
  151. user selects items by shift-clicking on them, flag bits around the
  152. terms selected are set to 1's.  The distance on each side of each
  153. selected term to set bits to 1's is a user option; for close
  154. proximity, only a few bits are be set; for more remotely
  155. linked terms, many bits are set.  The flag array can be
  156. held completely in memory, since it is a factor of 256 smaller than
  157. the original database file.  So, operations on it are very fast.
  158.  
  159.  
  160. CONCLUSIONS
  161.  
  162.      Ultimately, the Browser should be a natural extension of
  163. a user's memory.  It thus must be both fast and simple.  In order
  164. to be used, it must also be cheap, both in acquisition cost and in
  165. the cost of getting data into and out of it.  With a simple enough
  166. programming philosophy, and modern hardware and systems software,
  167. that goal should achievable.
  168.  
  169.      "Make everything as simple as possible, but no simpler."
  170.            - A. Einstein
  171.  
  172.  
  173.